package com.twu.biblioteca;

import java.util.Scanner;

/**
 * Created by phazel on 13/04/14.
 */
public class MainMenu
{
    Library lib = new Library();
    Scanner kb;

    public void display()
    {
        kb = new Scanner(System.in);

        while(true)
        {
            printMenuItems();
            System.out.print("\nEnter selection: ");
            String input = kb.nextLine();
            char selection = input.charAt( 0 );

            try
            {
                if( selection == 'a' )
                {
                    listBooks();
                }
                else if( selection == 'b')
                {
                    checkoutBook();
                }
                else if( selection == 'c' )
                {
                    returnBook();
                }
                else if( selection == 'q' || selection == 'Q' )
                {
                    System.out.println( "Quitting Biblioteca" );
                    break;
                }
                else
                {
                    System.out.println("Select a valid option!");
                }
            }
            catch(Exception e)
            {
                System.out.println("Select a valid option!");
            }
        }

        kb.close();
    }

    private void printMenuItems()
    {
        System.out.println("\n***** Main Menu *****\n");
        System.out.println("a. List Books");
        System.out.println("b. Checkout a book");
        System.out.println("c. Return a book");
    }

    // Menu option 'a'
    private void listBooks()
    {
        lib.list();
    }

    //Menu option 'b'
    private void checkoutBook()
    {
        lib.checkoutBook();
    }

    //Menu option 'c'
    private void returnBook()
    {
        lib.returnBook();
    }
}
